﻿@using Smartstore.Web.Models.Orders;

@model ShipmentDetailsModel

@{
    Assets.AppendTitleParts(T("PageTitle.ShipmentDetails"));

    async Task RenderAddress(AddressModel address)
    {
        <div class="mb-2">
            @Html.Raw(address.FormattedAddress)
        </div>
        <div class="email">
            <span class="pr-1">@T("Order.Email"):</span>
            <span>@address.Email</span>
        </div>
        <div sm-if="address.PhoneEnabled && address.PhoneNumber.HasValue()" class="phone">
            <span class="pr-1">@T("Order.Phone"):</span>
            <span>@address.PhoneNumber</span>
        </div>
        <div sm-if="address.FaxEnabled && address.FaxNumber.HasValue()" class="fax">
            <span class="pr-1">@T("Order.Fax"):</span>
            <span>@address.FaxNumber</span>
        </div>
    }
}

<div class="page shipment-details">
    <div class="page-title">
        <h1 class="h2">
            @T("Order.Shipments.Information", Model.Id)
        </h1>
    </div>

    <div class="page-body">
        <div class="card card-body shipment-box mb-4">
            <div class="row">
                <div class="col-6 col-md-4">
                    <h5>@T("Order.Shipments.Order#")</h5>
                    <p>
                        <a asp-action="Details" asp-controller="Order" asp-route-id="@Model.Order.Id">@Model.Order.Id</a>
                    </p>

                    <h5>@T("Order.Shipments.ShippedDate")</h5>
                    <p>
                        @if (Model.ShippedDate.HasValue)
                        {
                            @Model.ShippedDate.Value.ToNativeString("D")
                        }
                        else
                        {
                            <span class="text-muted">@T("Order.Shipments.ShippedDate.NotYet")</span>
                        }
                    </p>

                    <h5>@T("Order.Shipments.DeliveryDate")</h5>
                    <p>
                        @if (Model.DeliveryDate.HasValue)
                        {
                            @Model.DeliveryDate.Value.ToNativeString("D")
                        }
                        else
                        {
                            <span class="text-muted">@T("Order.Shipments.DeliveryDate.NotYet")</span>
                        }
                    </p>
                </div>
                <div class="col-6 col-md-4">
                    <h5>@T("Order.Shipments.ShippingMethod")</h5>
                    <p>@Model.Order.ShippingMethod</p>

                    @if (Model.TrackingNumber.HasValue())
                    {
                        <h5>@T("Order.Shipments.TrackingNumber")</h5>
                        <p>
                            @if (Model.TrackingNumberUrl.HasValue())
                            {
                                <a href="@Model.TrackingNumberUrl" target="_blank" class="tracking-url" rel="nofollow">@Model.TrackingNumber</a>
                            }
                            else
                            {
                                @Model.TrackingNumber
                            }
                        </p>
                    }
                </div>
                <div class="col-12 col-md-4">
                    <h5>@T("Order.Shipments.ShippingAddress")</h5>
                    @{ await RenderAddress(Model.Order.ShippingAddress); }
                </div>
            </div>
        </div>

        <fieldset sm-if="Model.Items.Any()" class="content-group">
            <h4 class="mb-3">@T("Order.Shipments.Product(s)")</h4>

            <div class="products-box table-responsive">
                <table class="table table-hover">
                    <colgroup>
                        <col sm-if="Model.ShowSku" width="1" />
                        <col />
                        <col />
                    </colgroup>
                    <thead>
                        <tr>
                            <th sm-if="Model.ShowSku">@T("Order.Shipments.Product(s).SKU")</th>
                            <th>@T("Order.Shipments.Product(s).Name")</th>
                            <th class="text-center">@T("Order.Shipments.Product(s).Quantity")</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var item in Model.Items)
                        {
                            <tr>
                                <td sm-if="Model.ShowSku">@item.Sku</td>
                                <td>
                                    <div><a href="@item.ProductUrl" title="@T("Products.Details")" sm-language-attributes-for="item.ProductName">@item.ProductName</a></div>
                                    <div sm-if="item.AttributeInfo.HasValue()" class="attributes text-muted mt-1">
                                        @Html.Raw(item.AttributeInfo)
                                    </div>
                                </td>
                                <td class="text-center">
                                    @item.QuantityShipped
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
        </fieldset>

        <div sm-if="Model.ShipmentStatusEvents.Any()" class="shipment-status-events">
            <h4 class="mb-3">@T("Order.ShipmentStatusEvents")</h4>

            <div class="shipment-status-events-box table-responsive">
                <table class="table table-hover">
                    <thead>
                        <tr>
                            <th>@T("Order.ShipmentStatusEvents.Event")</th>
                            <th>@T("Order.ShipmentStatusEvents.Location")</th>
                            <th>@T("Order.ShipmentStatusEvents.Country")</th>
                            <th>@T("Common.Date")</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (var item in Model.ShipmentStatusEvents)
                        {
                            <tr>
                                <td>@item.EventName</td>
                                <td>@item.Location</td>
                                <td>@item.Country</td>
                                <td>
                                    @if (item.Date.HasValue)
                                    {
                                        @item.Date.Value.ToNativeString("D")
                                    }
                                </td>
                            </tr>
                        }
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
